package com.ufo.dis.service.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.ufo.dis.service.service.HdfsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ufo.dis.service.entity.UserEntity;
import com.ufo.dis.service.service.UserService;
import com.ufo.dis.service.common.utils.PageUtils;
import com.ufo.dis.service.common.utils.R;



/**
 * 
 *
 * @author ufo
 * @email 2575829997@gmail.com
 * @date 2020-06-05 16:22:16
 */
@RestController
@RequestMapping("service/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    HdfsService hdfsService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/login")
    public R login(@RequestBody UserEntity user){
       Boolean login=userService.logintf(user);
         if(login) {
             return R.ok();
         }
         else{
             return R.error("登录错误");
         }
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{username}")
    public R info(@PathVariable("username") String username){
		UserEntity user = userService.getById(username);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserEntity user){
		userService.save(user);

        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] usernames){
		userService.removeByIds(Arrays.asList(usernames));
        return R.ok();
    }

}
